<style lang="less">
    @import "reconsideration.less";
</style>
<template>
    <div class="reconsideration" >
        <return-reason  :returnRea="returnData" v-model="remindVisible" @shutdown="modifyRemind"/>
        <Collapse v-model="values" style="padding: 15px">
            <Row>
                <div class="line">
                    <Button @click="closeThis" icon="md-return-left" type="primary">返回</Button>
                    <Button icon="md-image" type="primary">
                        <DynamicLink component="projects/afs-core-business/pages/case/approve/task-detail/regular-approve/regularApproveDetail"
                                     :is-full="true" :params="{isLung:'true',taskId:this.stageId,applyNo:this.detailParams.applyNo,isAppear:this.detailParams.isAppear}" name="案件详情" page-title="案件详情">
                        </DynamicLink>
                    </Button>
                    <Button  icon="md-camera" type="primary">
                        <DynamicLink component="projects/basic/pages/image/file-audit/createFileAudit"
                                     :is-full="true" :params="{auditParam:this.auditParam,operate:this.isCheck,businessDic:[{value:'orderReconsider',title:'复议申请'}]}" name="影像资料" page-title="影像资料" >
                        </DynamicLink>
                    </Button>
                </div>
            </Row>
            <br/>
            <Panel name="1"  v-show="this.remindList !==undefined && this.remindList.length > 0 && this.detailParams.firstTrail">
                留言
                <div slot="content">
                    <Row >
                        <Table border  :columns="remindColums" :data="remindList">
                        </Table>
                    </Row>
                </div>
            </Panel>
            <Panel name="1"  v-show="this.findList !==undefined && this.findList.length > 0 && this.detailParams.lastTrail">
                留言
                <div slot="content">
                    <Row >
                        <Table border  :columns="remindColums" :data="findList">
                        </Table>
                    </Row>
                </div>
            </Panel>
            <Panel  name="2">
                <div slot="content">
                    <Row >
                        <Form :model="reconReasonInfo" :label-width="100" class="reconReasonForm" ref="reconReasonForm">
                            <FormItem label="经销商复议理由"prop="reconReason" >
                                <Input type="textarea" v-model="reconReasonInfo.reconReason"
                                       :rows="4"
                                       :disabled="true"
                                       style="width: 500px"
                                       class="msgTextarea"
                                       maxlength="512" />
                            </FormItem>
                        </Form>
                        <Row class="submitedApprove" :model="submitedApprove" v-if="this.detailParams.lastTrail && isCheck">
                            <Icon type="ios-contact" class="icon" :size="70"/>
                            <Card :bordered="false" style="width: 1000px">
                                <h3 slot="title">{{submitedApprove.disposeStaff+submitedApprove.approveSuggestName}}</h3>
                                <p v-show="submitedApprove.approveSuggest === this.suggestConst.check.val">{{"复议要求："+submitedApprove.approveReason}}</p>
                                <p>{{"复议意见："+submitedApprove.approveRemark}}</p>
                            </Card>
                        </Row>
                        <Row class="allApprove" v-for="record in allApprove" v-if="holiday">
                            <Icon type="ios-contact" class="icon" :size="70"/>
                            <Card :bordered="false" style="width: 1000px">
                                <h3 slot="title">{{record.disposeStaff + record.approveSuggestName}}</h3>
                                <p v-show="record.approveSuggest === 'suggestCheck' || record.approveSuggest === 'suggestCheckF'">{{"复议要求："+record.approveReason}}</p>
                                <p>{{"复议意见：" + (record.approveRemark === undefined ? '' :record.approveRemark)}}</p>
                            </Card>
                        </Row>
                        <Form :model="suggestData" :label-width="100" class="suggestForm" ref="suggestForm" v-if="isCheck">
                            <FormItem label="审批建议" prop="approveSuggest" class="suggestSelect">
                                <i-select class="formSelect" v-model="suggestData.approveSuggest" @on-select="suggestSelected" @on-change="getSuggestReasonDic(true)" >
                                    <i-option v-for="item in approveSuggestDic" :value="item.value">{{item.title}}</i-option>
                                </i-select>
                            </FormItem>
                            <FormItem label="复议要求"prop="approveReason" v-show="suggestData.approveSuggest == this.suggestConst.check.val">
                                <Input type="textarea" v-model="suggestData.approveReason"
                                       :rows="4"
                                       style="width: 500px"
                                       class="msgTextarea"
                                       placeholder="请输入复议要求" maxlength="300" />
                            </FormItem>
                            <FormItem label="复议意见"prop="approveRemark" >
                                <Input type="textarea" v-model="suggestData.approveRemark"
                                       :rows="4"
                                       style="width: 500px"
                                       class="msgTextarea"
                                       placeholder="请输入复议意见" maxlength="300" />
                                <Row style="margin-left: -10px">
                                    <Button class="tailButton normalButton"  size="small" @click="saveApprove">暂存</Button>
                                    <Button class="tailButton normalButton" size="small" @click="submitApprove">提交</Button>
                                    <Button class="tailButton normalButton" size="small" @click="modifyRemind(true)" v-show="isTrue">退回</Button>
                                </Row>
                            </FormItem>
                        </Form>
                    </Row>
                </div>
            </Panel>
        </Collapse>
    </div>
</template>

<script>
    import {
        setStatusIsOpen
    } from "@/projects/afs-core-business/api/afs-case/approve/approveTask";
    import {
        getByTypes
    } from "_p/basic/api/admin/datadic";
    import {getDictDataByType} from "../../../../../basic/api/admin/datadic";
    import {queryReconReason,submitApprove,queryReturnRemind,findReturnRemind,queryReconsiderStatus} from "../../../../api/afs-case/approve/reconsideration";
    import {queryApprove,saveApprove,querySubmitApprove,queryApproveReason,queryAllApprove} from "../../../../api/afs-case/approve/changeAssetsTask";
    import ReturnReason from "../return-reason/returnReason";
    export default {
        name: "",
        components: {ReturnReason},
        props: {
            applyNo: {
                required: false,
                default:()=>{
                    return '';
                }
            },
            stageId:{
                type:[String,Number],
                default:''
            }
        },
        data:function () {
            return {
                applyNumber:'',
                values:["1","2","3"],
                recording:false,
                isTrue:false,
                isCheck: false,
                dataDic:{},
                dicKeys: [
                    "msgType"
                ],
                remindList:[],
                findList:[],
                recordingList:[],
                suggestTemplateId:'',
                businessStatusIn: '',
                businessStateIn: '',
                businessStateInList: [
                    "approved",
                    "reject",
                    "repeal",
                    "conditionalApproval",
                    "cancelConditional"
                ],
                suggestTemplateData:[],
                recordHisData:[],
                suggestData:{},
                submitedApprove:{},
                remindColums:[
                    {title: "操作",key: "action",minWidth: 100,align: "center"},
                    {title: "留言类型",key: "remindType",minWidth: 100,align: "center"},
                    {title: "处理人",key: "disposeStaff",minWidth: 100,align: "center"},
                    {title: "处理时间",key: "approveEndTime",minWidth: 100,align: "center"},
                    {title: "处理意见",key: "approveRemark",minWidth: 100,align: "left"}
                ],
                reconReasonInfo:{},
                approveSuggestDicKey:'approveSuggest',
                approveSuggestDic:[],
                formRemarkTitle:'',
                reasonVisible:false,
                remarkVisible:false,
                submitLoading:false,
                holiday: false,
                isExecute: true,
                isImplement: false,
                allRecord:[],
                allApprove: [],
                reasonSelectMultiple:true,
                detailParams:{},
                changeList:[],
                remindVisible : false,
                returnData:{
                    applyNo: '',
                    stageId: '',
                    approveSuggest: '',
                },
                suggestConst: {
                    check: {
                        title: "建议同意",
                        val: "suggestCheck"
                    },
                    reject: {
                        title: "建议拒绝",
                        val:"suggestReject"
                    },
                    rejectFinal: {
                        title: "拒绝",
                        val:"suggestRejectF"
                    },
                    checkFinal: {
                        title: "通过",
                        val:"suggestCheckF"
                    },
                    sendBack:{
                        title:"退回",
                        val:"sendBack"
                    }
                },
                auditParam:{
                    busiNo:'',
                    belongNo:'',
                    busiNode:"orderReconsider"},
            }

        },
        methods: {
            //返回
            whenClose() {
                this.afs.afsEmit(this, "flushData");
            },

            showRecord() {
                this.loadRecordList();
                this.recording = true;
            },
            modifyRemind(val){
                this.returnData.applyNo = this.detailParams.applyNo;
                this.returnData.stageId = this.detailParams.stageId;
                this.remindVisible=val;
            },
            getDic(v) {
                let dic = []
                switch (v) {
                    case "msgType":
                        dic = this.dataDic.msgType;
                        break;
                    default:
                }
                return dic;
            },
            initDataDic() {
                let self = this;
                getByTypes(this.dicKeys).then(res => {
                    if (res.code === "0000" && res.data) {
                        self.dataDic = res.data;
                    }
                });
            },
            //获取复议申请理由
            getReconReason(){
                let params = {
                    applyNo:this.detailParams.applyNo,
                    stageId:this.detailParams.stageId
                };
                queryReconReason(params).then(res => {
                    if (res.code == '0000') {
                        this.reconReasonInfo = res.data;
                    }
                })
            },
            //add by gjq 更新打开状态
            updateStatusIsOpen(){
                let params="";
                params={
                    approveStaff:this.detailParams.disposeCode,
                    stageId:this.detailParams.stageId,
                    processType:this.detailParams.processType,
                    applyNo:this.detailParams.applyNo
                }
                setStatusIsOpen(params).then(res => {
                    if (res.code === "0000") {
                    }
                });
            },
            init() {
                this.initDataDic();
                this.getSuggestDic();
                this.queryApprove();
                this.getReconReason();
                this.querySubmitApprove();
                this.queryReturnRemind();
                this.findReturnRemind();
                this.initQueryReconsiderStatus();
                this.queryAllApprove();
            },
            async initQueryReconsiderStatus(){
                let params = {
                    applyNo : this.detailParams.applyNo,
                    stageId : this.detailParams.stageId
                }
                let res = await queryReconsiderStatus(params).then(res => {
                    this.businessStateIn = res.data;
                })
                this.businessStateInList.forEach(list =>{
                    if (list === this.businessStateIn) {
                        this.holiday = true;
                    }
                })
            },
            queryAllApprove() {
                    let params = {
                        applyNo : this.detailParams.applyNo,
                        stageId : this.detailParams.stageId
                    }
                    queryAllApprove(params).then(res=>{
                        if (res.code === "0000") {
                            this.allRecord = res.data || [];
                            this.allRecord.forEach(record => {
                                if (record.approveSuggest !== "sendBack" && record.approveSuggest !== "suggestReformist") {
                                    this.allApprove.push(record)
                                }
                            })
                        }
                    });
            },
            afterRadioChange(val) {
            },
            getSuggestDic() {
                getDictDataByType(this.approveSuggestDicKey).then(res => {
                    if (res.code == '0000') {
                        // 默认复审
                        let suggestKey = [
                            this.suggestConst.check,
                            this.suggestConst.reject,
                        ];
                        // 只有一个审核节点，即是初审，也是终审
                        if (this.detailParams.firstTrail && this.detailParams.lastTrail) {
                            suggestKey = [
                                this.suggestConst.checkFinal,
                                this.suggestConst.rejectFinal,
                                this.returnData.approveSuggest="sendBackToDealer"
                            ]
                            // 终审
                        } else if (this.detailParams.lastTrail) {
                            suggestKey = [
                                this.suggestConst.checkFinal,
                                this.suggestConst.rejectFinal,
                                this.returnData.approveSuggest="sendBack"
                            ]
                            // 初审
                        } else if (this.detailParams.firstTrail) {
                            suggestKey = [
                                this.suggestConst.check,
                                this.suggestConst.reject,
                                this.returnData.approveSuggest="sendBackToDealer"

                            ]
                        }
                        suggestKey.forEach(suggestConst => {
                            res.data.forEach(suggest => {
                                if (suggestConst.val == suggest.value) {
                                    if(suggest.value=="suggestCheck"){
                                        suggest.title="建议通过";
                                    }
                                    if(suggest.value=="suggestCheckF"){
                                        suggest.title="通过";
                                    }
                                    this.approveSuggestDic.push(suggest);
                                }
                            })
                        })
                    }
                })
            },
            suggestSelected(val) {
                this.suggestData.approveSuggestName = val.label;
            },
            getSuggestReasonDic(clear) {
                if (this.suggestData && this.suggestData.approveSuggest) {
                    getDictDataByType(this.suggestData.approveSuggest).then(res => {
                        if (res.code == "0000") {
                            this.currentReasonDic = res.data || [];
                        }
                    });
                    if (clear) {
                        if (this.suggestData) {
                            this.suggestData.approveReason = "";
                            this.suggestData.approveMessage = "";
                        }
                    }
                    if (this.suggestData.approveSuggest == this.suggestConst.rejectFinal.val) {
                        this.reasonSelectMultiple = false;
                    }
                }
            },
            saveApprove() {
                this.suggestData.approveReason = this.suggestData.approveReason
                    ? this.suggestData.approveReason.toString()
                    : "";
                this.suggestData.applyNo = this.detailParams.applyNo;
                this.suggestData.stageId = this.detailParams.stageId;
                let params = {
                    approveRecord: this.suggestData
                };
                saveApprove(params).then(res => {
                    if (res.code == "0000") {
                        this.$Message.info("保存成功!")
                        this.suggestData = res.data.approveRecord;
                    }
                })
            },
            submitApprove() {
                if (this.detailParams.firstTrail){
                    if (!this.suggestData.approveSuggest) {
                        this.$Message.warning("请选择审批建议");
                        return;
                    }
                    if ((this.suggestData.approveSuggest == this.suggestConst.check.val || this.suggestData.approveSuggest == this.suggestConst.checkFinal.val) && !this.suggestData.approveReason){
                        this.$Message.warning("请填写审批要求");
                        return;
                    }
                    if (!this.suggestData.approveRemark){
                        this.$Message.warning("请填写审批意见");
                        return;
                    }
                }
                //部长审批意见需要和组长保持一致
                if (this.detailParams.lastTrail){
                        let lastApproveSuggest = this.submitedApprove.approveSuggest;
                        let currentApproveSuggest = this.suggestData.approveSuggest;
                            if ((lastApproveSuggest == this.suggestConst.check.val
                                && currentApproveSuggest != this.suggestConst.checkFinal.val)
                                || (lastApproveSuggest == this.suggestConst.reject.val
                                    && currentApproveSuggest != this.suggestConst.rejectFinal.val)) {
                                this.$Message.warning("审批建议必须与上一岗位审核意见保持一致.");
                                return false;
                            }
                }
                this.$Modal.confirm({
                    title: "确认",
                    content: "确认提交?",
                    onOk: () => {
                        if (this.detailParams.firstTrail) {
                            this.suggestData.approveReason = this.suggestData.approveReason ? this.suggestData.approveReason : "";
                        }
                        if (this.detailParams.lastTrail) {
                            this.suggestData.approveReason = this.submitedApprove.approveReason ? this.submitedApprove.approveReason : "";
                        }
                        this.suggestData.applyNo = this.detailParams.applyNo;
                        this.suggestData.stageId = this.detailParams.stageId;
                        let params = {
                            approveRecord: this.suggestData
                        };
                        submitApprove(params).then(res => {
                            if (res.code == "0000") {
                                this.$emit("whenClose");
                                this.$Message.info("提交成功!");
                                this.whenClose();
                                window.close();
                            }
                        })
                    }
                });
            },
            //查询组长已提交至部长的审批意见
            querySubmitApprove() {
                let params = {
                    applyNo: this.detailParams.applyNo,
                    stageId: this.detailParams.stageId
                };
                querySubmitApprove(params).then(res => {
                    if (res.code == "0000") {
                        this.submitedApprove = res.data || {};
                    }
                });
            },
            //查询部长退回至组长的意见
            queryReturnRemind(){
                if (this.detailParams.firstTrail) {
                    let params = {
                        applyNo: this.detailParams.applyNo,
                        stageId: this.detailParams.stageId,
                    }
                    queryReturnRemind(params).then(res => {
                        if (res.code === "0000") {
                            this.remindList = res.data;
                        }
                    });
                }
            },
            //部长页面展示自己退回的意见
            findReturnRemind(){
                if (this.detailParams.lastTrail) {
                    let params = {
                        applyNo : this.detailParams.applyNo,
                        stageId : this.detailParams.stageId,
                    }
                    findReturnRemind(params).then(res => {
                        if (res.code === "0000") {
                            this.findList = res.data;
                        }
                    })
                }
            },
            queryApproveReason(){
                if (this.isImplement) {
                    if (this.isExecute) {
                        if (this.detailParams.firstTrail) {
                            let params = {
                                applyNo: this.detailParams.applyNo,
                                stageId: this.detailParams.stageId,
                            }
                            queryApproveReason(params).then(res => {
                                if (res.code === "0000") {
                                    this.suggestData = res.data || {};
                                }
                            })
                        }
                    }
                }
            },
            //查询暂存数据
            queryApprove() {
                let params = {
                    applyNo: this.detailParams.applyNo,
                    stageId: this.detailParams.stageId
                };
                queryApprove(params).then(res => {
                    if (res.code == "0000") {
                        this.suggestData = res.data || {};
                        if (res.data) {
                            if (this.detailParams.lastTrail) {
                                this.isTrue = true
                                if ( this.suggestData.approveSuggest == this.suggestConst.check.val){
                                    this.suggestData.approveSuggest = this.suggestConst.checkFinal.val
                                }else if (this.suggestData.approveSuggest == this.suggestConst.reject.val){
                                    this.suggestData.approveSuggest = this.suggestConst.rejectFinal.val
                                }
                            }
                            this.getSuggestReasonDic(false);
                        }
                        if (this.suggestData.approveSuggest == undefined && this.suggestData.approveRemark == undefined) {
                            this.isImplement = true;
                        }
                        this.queryApproveReason();
                    }
                });
            },
            closeThis() {
                this.whenClose();
                window.close();
            },
        },
        mounted() {
            if (this.businessStatusIn === 'waitCheck') {
                this.isExecute = false;
            }
            this.init();
        },
        created() {
            this.detailParams.applyNo = this.applyNo;
            this.detailParams.stageId = this.stageId;
            this.detailParams = this.afs.getPageParams(this);
            this.isCheck = this.detailParams.isCheck === "true";
            this.auditParam.busiNo=this.detailParams.applyNo;
            this.auditParam.belongNo=this.detailParams.applyNo;
            if(this.detailParams.isCheck === "true"){
                this.updateStatusIsOpen();
            }
            if (this.detailParams.businessStatusIn !== undefined) {
                this.businessStatusIn = this.detailParams.businessStatusIn;
            }
        },
        computed:{
        }

    }
</script>

<style scoped>

</style>
